package HDFS;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;

import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;

/**
 * 使用IO文件上传
 */
public class Test_03 {
    public static void main(String[] args) throws URISyntaxException, IOException, InterruptedException {
        //创建配置文件对象
        Configuration conf  = new Configuration();
        //获取文件系统
        FileSystem fs = FileSystem.get(new URI("hdfs://bigdata211:9000"), conf, "root");

        //创建输入流
        FileInputStream fis  = new FileInputStream(new File("D:\\word.txt"));
        //创建输入流路径，需要给文件一个名字
        Path path = new Path("hdfs://bigdata211:9000/data/word1.txt");
        //创建输出流
        FSDataOutputStream fos = fs.create(path);

        //接受并拷贝
        IOUtils.copyBytes(fis,fos,4*1024,false);
        //关流
        IOUtils.closeStream(fos);
        IOUtils.closeStream(fis);
        //打印
        System.out.println("上传成功！");



    }

}
